//
//  PersonTableViewController.swift
//  FoodTracker
//
//  Created by 沈礼 on 15/9/19.
//  Copyright © 2015年 shenli. All rights reserved.
//

import UIKit

class PersonTableViewController: UITableViewController {

    var persons = [Person]()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        loadSampleData();

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    func loadSampleData() {
        let photo = UIImage(named: "me");
        let shenli = Person(name:"shenli",age:25, photo: photo)!;
        
        persons.append(shenli);
        
        print("person",persons[0].name);
    }

    
    override func numberOfSectionsInTableView(tabView: UITableView) -> Int {
        return 1;
    }
    
    
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return persons.count
    }
    
    
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cellIdentifier = "PersonTableViewCell";
        let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! PersonTableViewCell;
        
        print(persons);
        
        let person  = persons[indexPath.row];
        
        cell.personName.text = person.name
        cell.personImage.image = person.photo
        
        return cell

    }
    
    
    
}
